<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>新增产品信息</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="../../scripts/boot.js" type="text/javascript"></script>


    <style type="text/css">
        html,
        body {
            padding: 0;
            margin: 0;
            border: 0;
            height: 100%;
            overflow: hidden;
        }

        .asLabel .mini-textbox-border,
        .asLabel .mini-textbox-input,
        .asLabel .mini-buttonedit-border,
        .asLabel .mini-buttonedit-input,
        .asLabel .mini-textboxlist-border {
            border: 0;
            background: none;
            cursor: default;
        }

        .asLabel .mini-buttonedit-buttons,
        .asLabel .mini-buttonedit-button,
        .asLabel .mini-textboxlist-close {
            display: none;
        }

        .asLabel .mini-textboxlist-item {
            padding-right: 8px;
        }
    </style>
</head>

<body>

    <fieldset id="productinfoedit" style="width:590px;border:solid 1px #aaa;position:relative;">
        <legend>新增产品信息</legend>
        <table style="table-layout:fixed;">
            <tr>
                <td style="width:80px;">产品编号：</td>
                <td style="width:150px;"><input name="productId" class="mini-textbox asLabel" readOnly="true" />
                </td>
                <td style="width:80px;">产品名称：</td>
                <td style="width:150px;"><input name="productName" class="mini-textbox" readOnly="true" /></td>
            </tr>
            <tr>
                <td style="width:80px;">生产国家：</td>
                <td colspan="2">
                    <div name="country" class="mini-radiobuttonlist" repeatItems="1" repeatLayout="table"
                        repeatDirection="vertical" url="../../data/country.json" readOnly="true"></div>
                </td>
            </tr>
            <tr>
                <td>产品语言：</td>
                <td style="width:150px;"><input name="language" class="mini-textbox" readOnly="true" /></td>
            </tr>
            <tr>
                <td>上市时间：</td>
                <td><input name="createTime" class="mini-datepicker" readOnly="true" /></td>
                <td>产品用途：</td>
                <td style="width:150px;"><input name="productUsage" class="mini-combobox" emptyText="请选择"
                        url="../../data/productUsage.json" required="true" /></td>
            </tr>
            <tr>
                <td>备注：</td>
                <td colspan="4">
                    <mini-textarea name="remark" style="width:435px;"></mini-textarea>
                </td>
            </tr>
        </table>
    </fieldset>
    <div style="text-align:center;padding:10px;">
        <mini-button onclick="onOk" style="width:60px;margin-right:20px;">确定</mini-button>
        <mini-button onclick="onCancel" style="width:60px;">取消</mini-button>
    </div>
    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("productinfoedit");

        // 保存数据
        function SaveData() {
            var o = form.getData();

            form.validate();
            if (form.isValid() == false) return;

            var json = mini.encode(o);
            $.ajax({
                url: "../../productinfoaction",
                type: 'post',
                data: {
                    method: "update",
                    data: json
                },
                cache: false,
                success: function (text) {
                    var res = mini.decode(text);
                    if (res.code == 1) {
                        mini.alert(res.msg, "成功", window.CloseOwnerWindow);
                    } else {
                        mini.alert(res.msg);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        // 回显数据
        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);

                $.ajax({
                    url: "../../productinfoaction?method=getProductInfo&productId=" + data.productId,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);

                    }
                });
            }
        }
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (mini.confirm("是否保存数据？", "保存？", function (action) {
                    if (action == "ok") {
                        SaveData();
                    } else {
                        window.CloseOwnerWindow("cancel")
                    }
                })) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }

    </script>
</body>

</html>